package cn.com.api.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.api.entity.ApiT_promote;
import cn.com.api.entity.ApiTmember;
import cn.com.api.mapper.ApiT_promoteMapper;
import cn.com.api.service.ApiT_promoteService;
import cn.com.util.*;
import cn.com.util.*;

@Service
public class ApiT_promoteServiceImpl implements ApiT_promoteService {

	@Autowired
	private ApiT_promoteMapper apiT_promoteMapper;

	@Override
	public List<ApiT_promote> searchPromoteList(Map<String, Object> conditions, PageInfo pageInfo) {
		return apiT_promoteMapper.findByConditionsListPage(conditions, pageInfo);
	}

	@Override
	public ApiT_promote searchPromoteById(String id) {
		ApiT_promote promote = new ApiT_promote();
		if (!Util.isNull(id)) {
			promote = apiT_promoteMapper.searchPromoteById(id);
		}
		return promote;
	}

	@Override
	public void deletePromoteById(String id) {
		apiT_promoteMapper.deletePromoteById(id);
	}

	@Override
	public void addOrUpdatePromote(ApiT_promote t_promote) {
		Integer id = t_promote.getId();
		if (!Util.isNull(id)) {// 编辑
			apiT_promoteMapper.updateApiT_promote(t_promote);
		} else {// 添加
			t_promote.setStatus(0);
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			t_promote.setInsert_time(dateFormat.format(new Date()));
			apiT_promoteMapper.insertApiT_promote(t_promote);
		}
	}

	@Override
	public boolean checkInviteCode(ApiT_promote t_promote) {
		boolean flag = true;
		Integer count = apiT_promoteMapper.checkInviteCode(t_promote);
		if (count > 0) {
			flag = false;
		}
		return flag;
	}

	@Override
	public List<ApiT_promote> searchPromoteAppList(Map<String, Object> conditions, PageInfo pageInfo) {
		return apiT_promoteMapper.findPromoteAppByConditionsListPage(conditions, pageInfo);
	}

	@Override
	public List<ApiTmember> searchPromoteAppDetailList(Map<String, Object> conditions, PageInfo pageInfo) {
		return apiT_promoteMapper.findPromoteAppDetailByConditionsListPage(conditions, pageInfo);
	}

}
